package com.pms.servlet;
import java.io.IOException;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.pms.entity.File;
import com.pms.entity.Folder;
import com.pms.entity.Users;
import com.pms.service.FileService;
import com.pms.util.GetSession;


public class SinglefileServlet extends HttpServlet {


	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setCharacterEncoding("utf-8");
		
		request.getRequestDispatcher("/WEB-INF/singlefile.jsp").forward(request, response);
	}


	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setCharacterEncoding("utf-8");
		String fn=request.getParameter("filename");
		String fp=request.getParameter("filepath");
		fp=fp.substring(fp.lastIndexOf(".")+1);
		
		Folder fd = (Folder)GetSession.getSession(request).getAttribute("fdlist");
		String fdid=fd.getFolderid();
		
		Users user = (Users)GetSession.getSession(request).getAttribute("user");
		
		
		File f=new File();
		f.setFilename(fn);
		f.setUserid(user.getUser_id());
		f.setFolderid(fdid);
		
		new FileService().save(f);
		
		//response.sendRedirect("singlefileServlet.jspx");
	}

}
